package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SalaryFeedbackAddDTO;
import org.jsola.hr.dto.SalaryFeedbackUpdateDTO;
import org.jsola.hr.entity.SalaryFeedbackDO;
import org.jsola.hr.query.SalaryFeedbackQuery;
import org.jsola.hr.service.ISalaryFeedbackService;
import org.jsola.hr.vo.SalaryFeedbackVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 工资条反馈记录
 *
 * @author zhr
 */
@Component
public class SalaryFeedbackTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISalaryFeedbackService salaryFeedbackService;

    /**
     * 生成add测试数据
     * @return SalaryFeedbackAddDTO
     */
    public SalaryFeedbackAddDTO getSalaryFeedbackAddDTO(){
        SalaryFeedbackAddDTO salaryFeedbackAddDTO = new SalaryFeedbackAddDTO();
        salaryFeedbackAddDTO.setBillId(getRandomValue("varchar",32));
        salaryFeedbackAddDTO.setQuestion(getRandomValue("varchar",255));
        salaryFeedbackAddDTO.setAnswer(getRandomValue("varchar",255));
        salaryFeedbackAddDTO.setAnswerTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        salaryFeedbackAddDTO.setAnswerStatus(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        salaryFeedbackAddDTO.setCompanyId(getRandomValue("varchar",32));
        return salaryFeedbackAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SalaryFeedbackUpdateDTO
     */
    public SalaryFeedbackUpdateDTO getSalaryFeedbackUpdateDTO(SalaryFeedbackVO salaryFeedbackVO){
        return salaryFeedbackService.selectDOById(salaryFeedbackVO.getId(), SITE_ID).to(SalaryFeedbackUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SalaryFeedbackQuery
     */
    public SalaryFeedbackQuery getSalaryFeedbackQuery() {
        SalaryFeedbackQuery salaryFeedbackQuery = new SalaryFeedbackQuery();
        List<SalaryFeedbackDO> salaryFeedbackDOList = salaryFeedbackService.list(new SalaryFeedbackDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(salaryFeedbackDOList)) {
            SalaryFeedbackDO salaryFeedbackDO = salaryFeedbackDOList.get(0);
            salaryFeedbackQuery = salaryFeedbackDO.to(SalaryFeedbackQuery.class);
            if (salaryFeedbackDO.getAnswerTime() != null) {
                salaryFeedbackQuery.setAnswerTimeStart(DateKit.getBeforeDay(salaryFeedbackDO.getAnswerTime(),-1));
                salaryFeedbackQuery.setAnswerTimeEnd(DateKit.getBeforeDay(salaryFeedbackDO.getAnswerTime(),1));
            }
        }
        return salaryFeedbackQuery;
    }

    /**
     * 保存示例
     * @return SalaryFeedbackVO
     */
    public SalaryFeedbackVO saveSalaryFeedbackExample(){
        SalaryFeedbackAddDTO addDTO = this.getSalaryFeedbackAddDTO();
        SalaryFeedbackVO salaryFeedbackVO = salaryFeedbackService.save(addDTO,buildTokenUser());
        return salaryFeedbackVO;
    }


}

